home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1996 #15
/
Monster Media Number 15 (Monster Media)(July 1996).ISO
/
prog_gen
/
freeli10.zip
/
FREELIB3.ASX
< prev
next >
Wrap
Text File
|
1996-04-20
|
65KB
|
2,282 lines
~~~C_TXMAIN
Ideal
Include "textmac.inc" ;Include macros
Public CurSeg, W_X1, W_Y1, W_X2, W_Y2, W_Rel, Attr
Public inittext, closetext, clrscr, setcolor, getcolor
Model Tiny
P186
CodeSeg
;****************** Data Section
EGAPal dw 8010h,0000h,0101h ;EGA palette
dw 0202h,0303h,0404h
dw 0505h,0606h,0707h
dw 0808h,0909h,0A0Ah
dw 0B0Bh,0C0Ch,0D0Dh
dw 0E0Eh,0F2Fh
DACPal db 0,0,0,0,37,0,0,63 ;DAC palette: New color set
db 0,37,63,37,0,0,63 ;with much more variety than
db 37,0,37,63,0,63,46 ;the standard EGA color set.
db 46,46,27,27,27,63 ;Also allows XOR cursor 07h
db 0,0,63,37,0,63,63 ;with 67% minimum contrast
db 0,0,37,63,0,0,37 ;and 75% average contrast.
db 0,63,63,63,63,63
CurSeg dw 0 ;Current segment
W_X1 dw 0 ;Window values
W_Y1 dw 0
W_X2 dw 0
W_Y2 dw 0
W_Rel dw 0
Attr dw 0 ;Current attribute
;****************** inittext() -- Init text system
;void inittext(void);
Proc inittext
pusha ;Save all registers
push es
push 0A000h ;ES = video memory
pop es
mov ax,3 ;Set 80x25 text mode
int 10h
mov ax,1114h ;Load standard 8x16 font
xor bl,bl
int 10h
call SetSize ;Set resolution
mov dx,03D4h ;CRTC port
mov ax,4013h ;Fake 128 chars
out dx,ax ;for efficiency
mov dx,03DAh ;IS1 port
in al,dx ;Reset AC
mov dx,03C0h ;AC port
mov si,offset EGAPal ;Send palette
mov cx,34 ;via REP OUTSB
rep outsb
mov dx,03C8h ;DACWA port
xor al,al ;Set address 0
out dx,al
inc dx ;DACD port
mov si,offset DACPal ;Send palette
mov cx,48 ;via REP OUTSB
rep outsb
mov [W_X2],89 ;Set variables:
mov [W_Y2],33 ;W_X2, W_Y2...
xor ax,ax
mov [W_X1],ax ;W_X1...
mov [W_Y1],ax ;W_Y1...
mov [W_Rel],ax ;W_Rel...
mov [Attr],07h ;Attr...
mov [CurSeg],es ;CurSeg...
xor di,di ;Clear video memory
mov cx,8000h
mov ax,0720h
rep stosw
in_done: pop es ;Restore registers
popa
ret ;Return
EndP inittext
;****************** closetext() -- Close text system
;void closetext(void);
Proc closetext
push ax ;Save AX
mov ax,3 ;Set text video mode
int 10h
pop ax ;Restore AX
ret ;Return
EndP closetext
;****************** clrscr() -- Clear entire screen
;void clrscr(void);
Proc clrscr
pusha ;Save registers
push es
mov es,[CurSeg] ;ES = video memory
xor di,di ;Clear video page
mov cx,2800h
mov ax,0720h
rep stosw
pop es ;Restore registers
popa
ret ;Return
EndP clrscr
;****************** SetSize -- Set 90x34 resolution
Proc SetSize
pusha ;Save all registers
mov dx,03C4h ;Sequencer Port
mov ax,0100h ;Synchronous reset
out dx,ax ;Send command
inc ax ;8 pixels/char
out dx,ax ;Send command
mov dx,03CCh ;Misc Output Read Port
in al,dx ;Read value
and al,0F3h ;Bits 2-3: 01 = 28MHz
or al,0C4h ;Bits 6-7: 11 = 480 scanlines
mov dx,03C2h ;Misc Output Write Port
out dx,al ;Send command
mov dx,03DAh ;Read this port to reset
in al,dx ;the Attribute Controller
mov dx,03C0h ;Attribute Controller Port
mov al,33h ;Horizontal Panning
out dx,al ;Select register
xor al,al ;Set Shift = 0
out dx,al ;Send command
mov dx,03D4h ;CRT Controller Port
mov si,offset Data90x34 ;Offset of CRTC data
mov cx,17 ;17 words
rep outsw ;Send data
mov dx,03C4h ;Sequencer Port
mov ax,0300h ;Restart Sequencer
out dx,ax ;Send command
mov si,offset DataOE ;Turning off Odd/Even...
mov dx,03C4h ;SC port
mov cx,2 ;Send 2 words to SC port
rep outsw
mov dx,03CEh ;GC port
mov cx,3 ;Send 3 words to GC port
rep outsw
push si ;Save SI
mov si,1 ;Setting a 14-line Font.
xor di,di ;Shifting up by 1
mov dx,256 ;All 256 chars
xor al,al ;Zero AL
SS_sfont: mov cx,14 ;14 bytes
seges rep movsb ;Shift memory
mov cx,18 ;18 bytes
add si,cx ;Next char slot
rep stosb ;Clear excess
dec dx ;Loop back
jnz SS_sfont
pop si ;Restoring Odd/Even...
mov dx,03C4h ;SC port
mov cx,2 ;Send 2 words to SC port
rep outsw
mov dx,03CEh ;GC port
mov cx,3 ;Send 3 words to GC port
rep outsw
popa ;Restore registers
ret ;Return
Data90x34 dw 00011h ;De-protect value
dw 06B00h,05901h,05A02h ;Horizontal CRTC data
dw 08E03h,06004h,08D05h
dw 00B06h,03E07h,04D09h ;Vertical CRTC data
dw 0EA10h,08C11h,0DF12h
dw 0E715h,00416h
dw 00C0Ah,00D0Bh ;Initial cursor type
DataOE dw 0402h,0704h,0204h ;Odd/Even release and
dw 0005h,0406h ;0A000h segment data
dw 0302h,0304h,0004h ;Odd/Even restore data
dw 1005h,0606h
EndP SetSize
;****************** setcolor() -- Set text attribute
;void setcolor(int at);
Proc setcolor
push bp ;Set up stack frame
mov bp,sp
push [bp+4] ;Set attribute
pop [Attr]
pop bp ;Delete stack frame
ret 2 ;Return
EndP setcolor
;****************** getcolor() -- Get text attribute
;int getcolor(void);
Proc getcolor
mov ax,[Attr] ;Get attribute
ret ;Return
EndP getcolor
End
~~~C_TXWIN
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Public setwin, clrwin, fbox
Model Tiny
P186
CodeSeg
;****************** setwin() -- Set text window position, type
;void setwin(int x1, int y1, int x2, int y2, int rel);
Proc setwin
push bp ;Set up stack frame
mov bp,sp
push [bp+12] ;Set W_X1
pop [W_X1]
push [bp+10] ;Set W_Y1
pop [W_Y1]
push [bp+8] ;Set W_X2
pop [W_X2]
push [bp+6] ;Set W_Y2
pop [W_Y2]
push [bp+4] ;Set W_Rel
pop [W_Rel]
pop bp ;Delete stack frame
ret 10 ;Return
EndP setwin
;****************** clrwin() -- Clear window
;void clrwin(void);
Proc clrwin
pusha ;Save all registers
mov ax,[W_X1] ;Get values
mov bx,[W_Y1]
mov cx,[W_X2]
mov dx,[W_Y2]
cmp [W_Rel],0 ;Relativity check
je clw_norel
xor ax,ax ;Adjust to window
xor bx,bx
sub cx,ax
sub dx,bx
clw_norel: push ax bx cx dx ' ' ;fbox(W_X1, W_Y1,
call fbox ; W_X2, W_Y2, ' ');
popa ;Restore registers
ret ;Return
EndP clrwin
;****************** fbox() -- Draw filled box
;void fbox(int x1, int y1, int x2, int y2, int ch);
Proc fbox
push bp ;Set up stack frame
mov bp,sp
pusha ;Save registers
push es
mov es,[CurSeg] ;ES = video memory
mov ax,[bp+12] ;Get values
mov bx,[bp+10]
mov cx,[bp+8]
mov dx,[bp+6]
cmp [W_Rel],0 ;Relativity check
je fbx_norel
add ax,[W_X1] ;Adjust to window
add bx,[W_Y1]
add cx,[W_X1]
add dx,[W_Y1]
fbx_norel: cmp ax,cx ;X1 > X2?
jle fbx_xok
xchg ax,cx ;Switch them
fbx_xok: cmp bx,dx ;Y1 > Y2?
jle fbx_yok
xchg bx,dx ;Switch them
fbx_yok: cmp ax,[W_X2] ;X1 > W_X2?
jg fbx_bad
cmp cx,[W_X1] ;X2 < W_X1?
jl fbx_bad
cmp bx,[W_Y2] ;Y1 > W_Y2?
jg fbx_bad
cmp dx,[W_Y1] ;Y2 < W_Y1?
jnl fbx_cx1
fbx_bad: jmp fbx_done
fbx_cx1: cmp ax,[W_X1] ;X1 < W_X1?
jnl fbx_cx2
mov ax,[W_X1] ;Fix X1
fbx_cx2: cmp cx,[W_X2] ;X2 > W_X2?
jng fbx_cy1
mov cx,[W_X2] ;Fix X2
fbx_cy1: cmp bx,[W_Y1] ;Y1 < W_Y1?
jnl fbx_cy2
mov bx,[W_Y1] ;Fix Y1
fbx_cy2: cmp dx,[W_Y2] ;Y2 > W_Y2?
jng fbx_cont
mov dx,[W_Y2] ;Fix Y2
fbx_cont: mov si,dx ;SI = Y distance
sub si,bx
inc si
mov dx,cx ;DX = X distance
sub dx,ax
inc dx
mov cx,bx ;BX, CX = X1, Y1
mov bx,ax
mov al,[bp+4] ;AL = char
mov ah,[byte Attr] ;AH = attr
fbx_loop: SET_ROW_CHA ;Draw row
inc cx ;Next line
dec si ;Loop back
jnz fbx_loop
fbx_done: pop es ;Restore registers
popa
pop bp ;Delete stack frame
ret 10 ;Return
EndP fbox
End
~~~C_TXPAGE
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Public setpage, getpage
Model Tiny
P186
CodeSeg
;****************** setpage() -- Set video page
;void setpage(int page);
Proc setpage
push bp ;Set up stack frame
mov bp,sp
pusha ;Save all registers
mov ax,[bp+4] ;AX = page number
db 0D4h,06h ;AAM 6 (TASM doesn't recognize it)
xor ah,ah ;this puts it between 0 and 5
push ax
imul ax,320 ;AX = segment
add ax,0A000h
mov [CurSeg],ax ;Store segment
pop bx ;BX = page number
imul bx,20 ;BX = high byte value
mov dx,03C4h ;CRTC port
mov al,0Ch ;Start Address High
mov ah,bl ;AH = high byte value
out dx,ax ;Send command
popa ;Restore registers
pop bp ;Delete stack frame
ret 2 ;Return
EndP setpage
;****************** getpage() -- Get video page
;int getpage(void);
Proc getpage
mov ax,[CurSeg] ;Get segment pointer
sub ax,0A000h ;Subtract video segment
shr ax,6 ;Divide by 64
db 0D4h,05h ;AAM 5 (TASM doesn't recognize it)
shr ax,8 ;now AX = page number
ret ;Return
EndP getpage
End
~~~C_THLINE
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Public hline
Model Tiny
P186
CodeSeg
;****************** hline() -- Draw horizontal line
;void hline(int x1, int x2, int y, int ch);
Proc hline
push bp ;Set up stack frame
mov bp,sp
push es ;Save registers
pusha
mov es,[CurSeg] ;ES = video memory
mov ax,[bp+10] ;Get values
mov bx,[bp+6]
mov cx,[bp+8]
cmp [W_Rel],0 ;Relativity check
je hl_norel
add ax,[W_X1] ;Adjust to window
add bx,[W_Y1]
add cx,[W_X1]
hl_norel: cmp ax,cx ;X1 > X2?
jle hl_xok
xchg ax,cx ;Switch them
hl_xok: cmp bx,[W_Y2] ;Y > W_Y2?
jg hl_done
cmp bx,[W_Y1] ;Y < W_Y1?
jl hl_done
cmp ax,[W_X2] ;X1 > W_X2?
jg hl_done
cmp cx,[W_X1] ;X2 < W_X1?
jl hl_done
hl_cx1: cmp ax,[W_X1] ;X1 < W_X1?
jnl hl_cx2
mov ax,[W_X1] ;Fix X1
hl_cx2: cmp cx,[W_X2] ;X2 > W_X2?
jng hl_cont
mov cx,[W_X2] ;Fix X2
hl_cont: mov [bp+10],ax ;Store end-points
mov [bp+6],bx
mov [bp+8],cx
mov bx,[bp+10] ;BX = X
mov cx,[bp+6] ;CX = Y
mov dx,[bp+8] ;DX = count
sub dx,bx
inc dx
mov al,[bp+4] ;AL = char
mov ah,[byte Attr] ;AH = attr
SET_ROW_CHA ;Draw row
hl_done: popa ;Restore registers
pop es
pop bp ;Delete stack frame
ret 8 ;Return
EndP hline
End
~~~C_TVLINE
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Public vline
Model Tiny
P186
CodeSeg
;****************** vline() -- Draw vertical line
;void vline(int y1, int y2, int x, int ch);
Proc vline
push bp ;Set up stack frame
mov bp,sp
push es ;Save registers
pusha
mov es,[CurSeg] ;ES = video memory
mov ax,[bp+10] ;Get values
mov bx,[bp+6]
mov cx,[bp+8]
cmp [W_Rel],0 ;Relativity check
je vl_norel
add ax,[W_Y1] ;Adjust to window
add bx,[W_X1]
add cx,[W_Y1]
vl_norel: cmp ax,cx ;Y1 > Y2?
jle vl_yok
xchg ax,cx ;Switch them
vl_yok: cmp bx,[W_X2] ;X > W_X2?
jg vl_done
cmp bx,[W_X1] ;X < W_X1?
jl vl_done
cmp ax,[W_Y2] ;Y1 > W_Y2?
jg vl_done
cmp cx,[W_Y1] ;Y2 < W_Y1?
jl vl_done
vl_cy1: cmp ax,[W_Y1] ;Y1 < W_Y1?
jnl vl_cy2
mov ax,[W_Y1] ;Fix Y1
vl_cy2: cmp cx,[W_Y2] ;Y2 > W_Y2?
jng vl_cont
mov cx,[W_Y2] ;Fix Y2
vl_cont: mov [bp+10],ax ;Store end-points
mov [bp+6],bx
mov [bp+8],cx
mov bx,[bp+6] ;BX = X
mov cx,[bp+10] ;CX = Y
mov dx,[bp+8] ;DX = count
sub dx,cx
inc dx
mov al,[bp+4] ;AL = char
mov ah,[byte Attr] ;AH = attr
SET_VROW_CHA ;Draw row
vl_done: popa ;Restore registers
pop es
pop bp ;Delete stack frame
ret 8 ;Return
EndP vline
End
~~~C_TXBOX
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Extrn hline:near, vline:near
Public box
Model Tiny
P186
CodeSeg
;****************** box() -- Draw box, single character
;void box(int x1, int y1, int x2, int y2, int ch);
Proc box
push bp ;Set up stack frame
mov bp,sp
pusha ;Save registers
mov ax,[bp+12] ;Get values
mov bx,[bp+10]
mov cx,[bp+8]
mov dx,[bp+6]
cmp [W_Rel],0 ;Relativity check
je bx_norel
add ax,[W_X1] ;Adjust to window
add bx,[W_Y1]
add cx,[W_X1]
add dx,[W_Y1]
bx_norel: mov [bp+12],ax ;Store values
mov [bp+10],bx
mov [bp+8],cx
mov [bp+6],dx
mov si,[bp+4] ;SI = char
push ax bx cx si ;Draw top line
call hline
push ax cx dx si ;Draw bottom line
call hline
push bx dx ax si ;Draw left line
call vline
push bx dx cx si ;Draw right line
call vline
popa ;Restore registers
pop bp ;Delete stack frame
ret 10 ;Return
EndP box
End
~~~C_STYBOX
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Extrn hline:near, vline:near
Public hsline, vsline, sbox
Model Tiny
P186
CodeSeg
STYLEdata db ' ' ;Box style data: (0 = blank)
db '─│┌┐└┘' ;┌─┬─┐ ╔═╦═╗ ╒═╤═╕ ╓─╥─╖
db '═║╔╗╚╝' ;├─┼─┤ ╠═╬═╣ ╞═╪═╡ ╟─╫─╢
db '═│╒╕╘╛' ;└─┴─┘ ╚═╩═╝ ╘═╧═╛ ╙─╨─╜
db '─║╓╖╙╜' ; 1 2 3 4
;****************** sbox() -- Draw box, with style
;void sbox(int x1, int y1, int x2, int y2, int style);
Proc sbox
push bp ;Set up stack frame
mov bp,sp
pusha ;Save registers
push es
mov es,[CurSeg] ;ES = video memory
mov ax,[bp+12] ;Get values
mov bx,[bp+10]
mov cx,[bp+8]
mov dx,[bp+6]
cmp [W_Rel],0 ;Relativity check
je sbx_norel
add ax,[W_X1] ;Adjust to window
add bx,[W_Y1]
add cx,[W_X1]
add dx,[W_Y1]
sbx_norel: mov [bp+12],ax ;Store values
mov [bp+10],bx
mov [bp+8],cx
mov [bp+6],dx
mov si,[bp+4] ;SI = style
inc ax ;Set up for hsline
dec cx
push ax cx bx si ;Draw top line
call hsline
push ax cx dx si ;Draw bottom line
call hsline
dec ax ;Set up for vsline
inc cx
inc bx
dec dx
push bx dx ax si ;Draw left line
call vsline
push bx dx cx si ;Draw right line
call vsline
mov bx,[bp+4] ;AL = TLC char
imul bx,6
mov al,[STYLEdata+bx+2]
mov bx,[bp+12] ;Draw TLC . . .
mov cx,[bp+10]
cmp cx,[W_Y1] ;Clip character
jl sbx_skip2
cmp cx,[W_Y2]
jg sbx_skip2
cmp bx,[W_X1]
jl sbx_skip1
cmp bx,[W_X2]
jg sbx_skip1
mov ah,[byte Attr] ;AH = attr
SET_CHA ;Draw character
sbx_skip1: mov bx,[bp+4] ;AL = TRC char
imul bx,6
mov al,[STYLEdata+bx+3]
mov bx,[bp+8] ;Draw TRC . . .
mov cx,[bp+10]
cmp bx,[W_X1] ;Clip character
jl sbx_skip2
cmp bx,[W_X2]
jg sbx_skip2
mov ah,[byte Attr] ;AH = attr
SET_CHA ;Draw character
sbx_skip2: mov bx,[bp+4] ;AL = LLC char
imul bx,6
mov al,[STYLEdata+bx+4]
mov bx,[bp+12] ;Draw LLC . . .
mov cx,[bp+6]
cmp cx,[W_Y1] ;Clip character
jl sbx_done
cmp cx,[W_Y2]
jg sbx_done
cmp bx,[W_X1]
jl sbx_skip3
cmp bx,[W_X2]
jg sbx_skip3
mov ah,[byte Attr] ;AH = attr
SET_CHA ;Draw character
sbx_skip3: mov bx,[bp+4] ;AL = LRC char
imul bx,6
mov al,[STYLEdata+bx+5]
mov bx,[bp+8] ;Draw LRC . . .
mov cx,[bp+6]
cmp bx,[W_X1] ;Clip character
jl sbx_done
cmp bx,[W_X2]
jg sbx_done
mov ah,[byte Attr] ;AH = attr
SET_CHA ;Draw character
sbx_done: pop es ;Restore registers
popa
pop bp ;Delete stack frame
ret 10 ;Return
EndP sbox
;****************** hsline() -- Draw horizontal style line
;void hsline(int x1, int x2, int y, int style);
Proc hsline
push bp ;Set up stack frame
mov bp,sp
pusha ;Save all registers
mov bx,[bp+4] ;AL = HL char
imul bx,6
mov al,[STYLEdata+bx]
xor ah,ah
push [bp+10] [bp+8] ;Push args
push [bp+6] ax
call hline ;Draw line
popa ;Restore registers
pop bp ;Delete stack frame
ret 8 ;Return
EndP hsline
;****************** vsline() -- Draw vertical style line
;void vsline(int y1, int y2, int x, int style);
Proc vsline
push bp ;Set up stack frame
mov bp,sp
pusha ;Save all registers
mov bx,[bp+4] ;AL = VL char
imul bx,6
mov al,[STYLEdata+bx+1]
xor ah,ah
push [bp+10] [bp+8] ;Push args
push [bp+6] ax
call vline ;Draw line
popa ;Restore registers
pop bp ;Delete stack frame
ret 8 ;Return
EndP vsline
End
~~~C_TEXCUR
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Public gotoxy, getx, gety, setctype, getctype
Model Tiny
P186
CodeSeg
;****************** gotoxy() -- Set cursor position
;void gotoxy(int x, int y);
Proc gotoxy
push bp ;Set up stack frame
mov bp,sp
pusha ;Save all registers
mov ax,[bp+6] ;Get values
mov bx,[bp+4]
cmp [W_Rel],0 ;Relativity check
je xy_norel
add ax,[W_X1] ;Adjust to window
add bx,[W_Y1]
xy_norel: cmp ax,[W_X1] ;Clip to window
jl xy_done
cmp ax,[W_X2]
jg xy_done
cmp bx,[W_Y1]
jl xy_done
cmp bx,[W_Y2]
jg xy_done
shl bx,7 ;Get CRTC address
add bx,ax
mov dx,03D4h ;CRTC port
mov al,0Eh ;Cursor Loc High
mov ah,bh ;Set value
out dx,ax
inc ax ;Cursor Loc Low
mov ah,bl ;Set value
out dx,ax
xy_done: popa ;Restore registers
pop bp ;Delete stack frame
ret 4 ;Return
EndP gotoxy
;****************** getx() -- Get cursor X position
;int getx(void);
Proc getx
push dx ;Save DX
mov dx,03D4h ;CRTC port
mov al,0Fh ;Cursor Loc Low
out dx,al ;Set register
inc dx ;Data port
in al,dx ;Read value
and ax,127 ;Get X position
cmp [W_Rel],0 ;Relativity check
je gx_done
sub ax,[W_X1] ;Adjust to window
gx_done: pop dx ;Restore DX
ret ;Return
EndP getx
;****************** gety() -- Get cursor Y position
;int gety(void);
Proc gety
push dx ;Save DX
mov dx,03D4h ;CRTC port
mov al,0Eh ;Cursor Loc High
out dx,al ;Set register
inc dx ;Data port
in al,dx ;Read value
mov ah,al
dec dx ;Index port
mov al,0Fh ;Cursor Loc Low
out dx,al ;Set register
inc dx ;Data port
in al,dx ;Read value
shr ax,7 ;Get Y position
and ax,127
cmp [W_Rel],0 ;Relativity check
je gy_done
sub ax,[W_Y1] ;Adjust to window
gy_done: pop dx ;Restore DX
ret ;Return
EndP gety
;****************** setctype() -- Set cursor type
;void setctype(int type);
Proc setctype
push bp ;Set up stack frame
mov bp,sp
pusha ;Save all registers
mov bx,[bp+4] ;Get type
mov dx,03D4h ;CRTC port
mov al,0Ah ;Cursor Start
mov ah,bh ;Set value
out dx,ax
inc ax ;Cursor End
mov ah,bl ;Set value
out dx,ax
popa ;Restore registers
pop bp ;Delete stack frame
ret 2 ;Return
EndP setctype
;****************** getctype() -- Get cursor type
;int getctype(void);
Proc getctype
push dx ;Save DX
mov dx,03D4h ;CRTC port
mov al,0Ah ;Cursor Start
out dx,al ;Set register
inc dx ;Data port
in al,dx ;Read value
mov ah,al
dec dx ;Index port
mov al,0Bh ;Cursor End
out dx,al ;Set register
inc dx ;Data port
in al,dx ;Read value
pop dx ;Restore DX
ret ;Return
EndP getctype
End
~~~C_TPUTS
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Public tputs
Model Tiny
P186
CodeSeg
;****************** tputs() -- Put string
;void tputs(int x, int y, char *str);
Proc tputs
push bp ;Set up stack frame
mov bp,sp
push es ;Save registers
pusha
mov es,[CurSeg] ;ES = video memory
mov ax,[bp+8] ;Get values
mov bx,[bp+6]
cmp [W_Rel],0 ;Relativity check
je ps_norel
add ax,[W_X1] ;Adjust to window
add bx,[W_Y1]
mov [bp+8],ax
mov [bp+6],bx
ps_norel: cmp bx,[W_Y1] ;Y < W_Y1?
jl ps_done
cmp bx,[W_Y2] ;Y > W_Y2?
jg ps_done
cmp ax,[W_X2] ;X > W_X2?
jg ps_done
shl bx,8 ;DI = offset
add bx,ax
add bx,ax
mov di,bx
mov si,[bp+4] ;SI = string
mov bx,[bp+8] ;BX = X
mov cx,[W_X1] ;CX = W_X1
mov dx,[W_X2] ;DX = W_X2
mov ah,[byte Attr] ;AH = color
ps_loop: lodsb ;Load char
test al,al ;Null, done
je ps_done
cmp bx,cx ;Off left, loop
jl ps_lb
cmp bx,dx
jg ps_done ;Off right, quit
mov [es:di],ax ;Write char
ps_lb: inc di ;Advance pointer
inc di
inc bx ;Advance X
jmp ps_loop ;Loop back
ps_done: popa ;Restore registers
pop es bp ;Delete stack frame
ret 6 ;Return
EndP tputs
End
~~~C_TPRINT
Ideal
Extrn sprintf:near,tputs:near,allocmem:near,freemem:near
Public tprintf
Model Tiny
CodeSeg
P186
;****************** tprintf() -- Print formatted string
;void tprintf(int x, int y, char *fmt, void *args);
x equ bp+10
y equ bp+8
fmt equ bp+6
args equ bp+4
Proc tprintf
push bp ;Set up stack frame
mov bp,sp
pusha ;Save all registers
push 400 ;Allocate a 400 byte buffer
call allocmem
test ax,ax ;Out of memory?
jz tp_done
mov bx,ax ;BX = buffer
push bx [fmt] [args] ;sprintf() into buffer
call sprintf
push [x] [y] bx ;Print string to screen
call tputs
push bx
call freemem ;Free memory
tp_done: popa ;Restore registers
pop bp ;Delete stack frame
ret 8 ;Return
EndP tprintf
End
~~~C_TXCHAR
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Public setch, setat, setcha, readcha
Model Tiny
P186
CodeSeg
;****************** setch() -- Write character
;void setch(int x, int y, int ch);
Proc setch
push bp ;Set up stack frame
mov bp,sp
pusha ;Save all registers
push es
mov es,[CurSeg] ;ES = video memory
mov bx,[bp+8] ;Get values
mov cx,[bp+6]
cmp [W_Rel],0 ;Relativity check
je sch_norel
add bx,[W_X1] ;Adjust to window
add cx,[W_Y1]
sch_norel: cmp bx,[W_X1] ;X < W_X1?
jl sch_done
cmp bx,[W_X2] ;X > W_X2?
jg sch_done
cmp cx,[W_Y1] ;Y < W_Y1?
jl sch_done
cmp cx,[W_Y2] ;Y > W_Y2?
jg sch_done
mov al,[bp+4] ;AL = char
SET_CH ;Write char
sch_done: pop es ;Restore registers
popa
pop bp ;Delete stack frame
ret 6 ;Return
EndP setch
;****************** setat() -- Write attribute
;void setat(int x, int y, int at);
Proc setat
push bp ;Set up stack frame
mov bp,sp
pusha ;Save all registers
push es
mov es,[CurSeg] ;ES = video memory
mov bx,[bp+8] ;Get values
mov cx,[bp+6]
cmp [W_Rel],0 ;Relativity check
je sa_norel
add bx,[W_X1] ;Adjust to window
add cx,[W_Y1]
sa_norel: cmp bx,[W_X1] ;X < W_X1?
jl sa_done
cmp bx,[W_X2] ;X > W_X2?
jg sa_done
cmp cx,[W_Y1] ;Y < W_Y1?
jl sa_done
cmp cx,[W_Y2] ;Y > W_Y2?
jg sa_done
mov al,[bp+4] ;AL = attr.
SET_AT ;Write attr.
sa_done: pop es ;Restore registers
popa
pop bp ;Delete stack frame
ret 6 ;Return
EndP setat
;****************** setcha() -- Write char, attr.
;void setcha(int x, int y, int ch, int at);
Proc setcha
push bp ;Set up stack frame
mov bp,sp
pusha ;Save all registers
push es
mov es,[CurSeg] ;ES = video memory
mov bx,[bp+10] ;Get values
mov cx,[bp+8]
cmp [W_Rel],0 ;Relativity check
je sb_norel
add bx,[W_X1] ;Adjust to window
add cx,[W_Y1]
sb_norel: cmp bx,[W_X1] ;X < W_X1?
jl sb_done
cmp bx,[W_X2] ;X > W_X2?
jg sb_done
cmp cx,[W_Y1] ;Y < W_Y1?
jl sb_done
cmp cx,[W_Y2] ;Y > W_Y2?
jg sb_done
mov al,[bp+6] ;AL = char
mov ah,[bp+4] ;AH = attr.
SET_CHA ;Write char, attr.
sb_done: pop es ;Restore registers
popa
pop bp ;Delete stack frame
ret 8 ;Return
EndP setcha
;****************** readcha() -- Read character and attribute
;int readcha(int x, int y);
Proc readcha
push bp ;Set up stack frame
mov bp,sp
push es bx ;Save registers
mov es,[CurSeg] ;ES = video memory
mov ax,[bp+6] ;Get values
mov bx,[bp+4]
cmp [W_Rel],0 ;Relativity check
je rc_norel
add ax,[W_X1] ;Adjust to window
add bx,[W_Y1]
rc_norel: shl bx,8 ;Get offset
add bx,ax
add bx,ax
mov ax,[es:bx] ;Read char/attr
pop bx es ;Restore registers
pop bp ;Delete stack frame
ret 4 ;Return
EndP readcha
End
~~~C_GPTEXT
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Public gettext, puttext
Model Tiny
P186
CodeSeg
;****************** gettext() -- Get text image
;void gettext(void *buf, int x1, int y1, int x2, int y2);
Proc gettext
push bp ;Set up stack frame
mov bp,sp
push ds es ;Save registers
pusha
mov ds,[CurSeg] ;DS = video memory
push cs ;ES:DI = text buffer
pop es
mov di,[bp+12]
mov ax,[bp+10] ;Get values
mov bx,[bp+8]
mov cx,[bp+6]
mov dx,[bp+4]
cmp [cs:W_Rel],0 ;Relativity check
je gt_norel
add ax,[cs:W_X1] ;Adjust to window
add bx,[cs:W_Y1]
add cx,[cs:W_X1]
add dx,[cs:W_Y1]
gt_norel: cmp ax,cx ;Put them in order
jle $+3
xchg ax,cx
cmp bx,dx
jle $+4
xchg bx,dx
mov [bp+10],ax ;Save values
mov [bp+8],bx
mov [bp+6],cx
mov [bp+4],dx
mov si,[bp+8] ;SI = source offset
mov ax,[bp+10]
shl si,8
add si,ax
add si,ax
mov dx,[bp+6] ;DX = X distance
sub dx,[bp+10]
inc dx
mov bx,[bp+4] ;BX = Y distance
sub bx,[bp+8]
inc bx
mov ax,dx ;Store size
stosw
mov ax,bx
stosw
mov ax,256 ;AX = offset adjust
sub ax,dx
sub ax,dx
gt_loop: mov cx,dx ;Move line
rep movsw
add si,ax ;Advance pointers
dec bx ;Loop back
jnz gt_loop
gt_done: popa ;Restore registers
pop es ds
pop bp ;Delete stack frame
ret 10 ;Return
EndP gettext
;****************** puttext() -- Put text image
;void puttext(void *buf, int x, int y);
Proc puttext
push bp ;Set up stack frame
mov bp,sp
push es ;Save registers
pusha
mov es,[CurSeg] ;ES = video memory
mov si,[bp+8] ;SI = text buffer
mov ax,[bp+6] ;Get values
mov bx,[bp+4]
cmp [W_Rel],0 ;Relativity check
je pt_norel
add ax,[W_X1] ;Adjust to window
add bx,[W_Y1]
pt_norel: mov [bp+6],ax ;Save values
mov [bp+4],bx
lodsw ;CX = X distance
mov cx,ax
lodsw ;DX = Y distance
mov dx,ax
mov ax,[bp+6] ;Restore AX
add cx,ax ;CX, DX = X2, Y2
add dx,bx
dec cx
dec dx
cmp ax,[W_X1] ;Clip to window
jl pt_done
cmp bx,[W_Y1]
jl pt_done
cmp cx,[W_X2]
jg pt_done
cmp dx,[W_Y2]
jg pt_done
inc cx ;Restore distances
sub cx,ax
inc dx
sub dx,bx
mov bx,dx ;DX = X distance
mov dx,cx ;BX = Y distance
mov di,[bp+4] ;DI = dest. offset
mov ax,[bp+6]
shl di,8
add di,ax
add di,ax
mov ax,256 ;AX = offset adjust
sub ax,dx
sub ax,dx
pt_loop: mov cx,dx ;Move line
rep movsw
add di,ax ;Advance pointers
dec bx ;Loop back
jnz pt_loop
pt_done: popa ;Restore registers
pop es
pop bp ;Delete stack frame
ret 6 ;Return
EndP puttext
End
~~~C_MTEXT
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Public movetext
Model Tiny
P186
CodeSeg
;****************** movetext() -- Move window of text
;void movetext(int x1, int y1, int x2, int y2, int x, int y);
Proc movetext
push bp ;Set up stack frame
mov bp,sp
pusha ;Save registers
push ds es
mov ax,[CurSeg] ;DS, ES = video memory
mov ds,ax
mov es,ax
mov ax,[bp+14] ;Get values
mov bx,[bp+12]
mov cx,[bp+10]
mov dx,[bp+8]
mov si,[bp+6]
mov di,[bp+4]
cmp ax,cx ;Put them in order
jle $+3
xchg ax,cx
cmp bx,dx
jle $+4
xchg bx,dx
mov [bp+14],ax ;Save values
mov [bp+12],bx
mov [bp+10],cx
mov [bp+8],dx
mov [bp+6],si
mov [bp+4],di
mov ax,[bp+12] ;Greater offset, move from end
cmp ax,[bp+4] ;Lesser offset, move from start
jl mw_rev ;Same offset, do nothing
jg mw_for
mov ax,[bp+14]
cmp ax,[bp+6]
jl mw_rev
jg mw_for
jmp mw_done
mw_for: mov si,[bp+12] ;SI = source offset
mov ax,[bp+14]
shl si,8
add si,ax
add si,ax
mov di,[bp+4] ;DI = dest. offset
mov ax,[bp+6]
shl di,8
add di,ax
add di,ax
mov dx,[bp+10] ;DX = X distance
sub dx,[bp+14]
inc dx
mov bx,[bp+8] ;BX = Y distance
sub bx,[bp+12]
inc bx
mov ax,256 ;AX = offset adjust
sub ax,dx
sub ax,dx
mw_floop: mov cx,dx ;Move line
rep movsw
add si,ax ;Advance pointers
add di,ax
dec bx ;Loop back
jnz mw_floop
jmp mw_done
mw_rev: mov si,[bp+12] ;SI = source offset
mov ax,[bp+14]
shl si,8
add si,ax
add si,ax
mov di,[bp+4] ;DI = dest. offset
mov ax,[bp+6]
shl di,8
add di,ax
add di,ax
mov dx,[bp+10] ;DX = X distance
sub dx,[bp+14]
mov bx,[bp+8] ;BX = Y distance
sub bx,[bp+12]
mov ax,bx ;Move offsets to end
shl ax,8
add ax,dx
add ax,dx
add si,ax
add di,ax
inc dx ;Fix distances
inc bx
mov ax,256 ;AX = offset adjust
sub ax,dx
sub ax,dx
std ;Direction is reverse
mw_rloop: mov cx,dx ;Move line
rep movsw
sub si,ax ;Advance pointers
sub di,ax
dec bx ;Loop back
jnz mw_rloop
mw_done: cld ;Clear direction flag
pop es ds ;Restore registers
popa
pop bp ;Delete stack frame
ret 12 ;Return
EndP movetext
End
~~~C_SCROLL
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Extrn movetext:near, hline:near
Extrn vline:near, clrwin:near
Public scroll
Model Tiny
P186
CodeSeg
;****************** scroll() -- Scroll window
;void scroll(int dir);
Proc scroll
push bp ;Set up stack frame
mov bp,sp
pusha ;Save registers
mov bx,[bp+4] ;Get direction
and bx,3 ;Jump to routine
add bx,bx
jmp [ScTable+bx]
sc_up: mov ax,[W_Y1] ;Window one line?
cmp ax,[W_Y2]
jne sc_cont1
jmp sc_tiny
sc_cont1: inc ax
push [W_X1] ax ;Push args
push [W_X2] [W_Y2]
push [W_X1] [W_Y1]
call movetext ;Scroll up
push [W_X1] [W_X2] ;Clear bottom line
push [W_Y2] ' '
call hline
jmp sc_done
sc_down: mov ax,[W_Y1] ;Window one line?
mov bx,[W_Y2]
cmp ax,bx
jne sc_cont2
jmp sc_tiny
sc_cont2: inc ax
dec bx
push [W_X1] [W_Y1] [W_X2]
push bx [W_X1] ax ;Push args
call movetext ;Scroll down
push [W_X1] [W_X2] ;Clear top line
push [W_Y1] ' '
call hline
jmp sc_done
sc_left: mov ax,[W_X1] ;Window one column?
cmp ax,[W_X2]
je sc_tiny
inc ax
push ax [W_Y1] ;Push args
push [W_X2] [W_Y2]
push [W_X1] [W_Y1]
call movetext ;Scroll left
push [W_Y1] [W_Y2] ;Clear right column
push [W_X2] ' '
call vline
jmp sc_done
sc_right: mov ax,[W_X1] ;Window one column?
mov bx,[W_X2]
cmp ax,bx
je sc_tiny
inc ax
dec bx
push [W_X1] [W_Y1] bx ;Push args
push [W_Y2] ax [W_Y1]
call movetext ;Scroll right
push [W_Y1] [W_Y2] ;Clear left column
push [W_X1] ' '
call vline
jmp sc_done
sc_tiny: call clrwin ;Clear window
sc_done: popa ;Restore registers
pop bp ;Delete stack frame
ret 2 ;Return
ScTable dw offset sc_up
dw offset sc_down
dw offset sc_left
dw offset sc_right
EndP scroll
End
~~~C_DILINE
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Extrn movetext:near, hline:near, vline:near
Public delline, insline
Model Tiny
P186
CodeSeg
;****************** delline() -- Delete line from window
;void delline(int y);
Proc delline
push bp ;Set up stack frame
mov bp,sp
pusha ;Save registers
mov ax,[bp+4]
cmp [W_Rel],0 ;Relativity check
je dl_norel
add ax,[W_Y1] ;Adjust to window
dl_norel: cmp ax,[W_Y1] ;Clip to window
jl dl_done
cmp ax,[W_Y2]
jg dl_done
je dl_clear
inc ax
push [W_X1] ax [W_X2] ;Push args
dec ax
push [W_Y2] [W_X1] ax
call movetext ;Scroll up
dl_clear: push [W_X1] [W_X2] ;Clear bottom line
push [W_Y2] ' '
call hline
dl_done: popa ;Restore registers
pop bp ;Delete stack frame
ret 2 ;Return
EndP delline
;****************** insline() -- Insert line in window
;void insline(int y);
Proc insline
push bp ;Set up stack frame
mov bp,sp
pusha ;Save registers
mov ax,[bp+4]
cmp [W_Rel],0 ;Relativity check
je il_norel
add ax,[W_Y1] ;Adjust to window
il_norel: cmp ax,[W_Y1] ;Clip to window
jl il_done
cmp ax,[W_Y2]
jg il_done
je il_clear
mov bx,ax ;BX = y - 1,
mov cx,[W_Y2] ;CX = W_Y2 - 1
inc bx
dec cx
push [W_X1] ax [W_X2] ;Push args
push cx [W_X1] bx
call movetext ;Scroll down
il_clear: push [W_X1] [W_X2] ;Clear bottom line
push ax ' '
call hline
il_done: popa ;Restore registers
pop bp ;Delete stack frame
ret 2 ;Return
EndP insline
End
~~~C_TGETLN
Ideal
Include "textmac.inc" ;Include macros
Include "textdat.inc" ;Include data
Extrn tputs:near,setctype:near,gety:near
Extrn gotoxy:near,getx:near,getctype:near
Extrn memset:near,hline:near
Public getline,setglchar
Model Tiny
P186
CodeSeg
;****************** setglchar() -- Set field fill char for getline()
;void setglchar(int chr);
chr equ bp+4
Proc setglchar
push bp ;Set up stack frame
mov bp,sp
push [chr] ;Set gl_fillchar
pop [gl_fillchar]
pop bp ;Delete stack frame
ret 2 ;Return
EndP setglchar
;****************** getline() -- Get line of text, with edit
;void getline(int x, int y, char *strp, int min, int max);
x equ bp+12
y equ bp+10
strp equ bp+8
min equ bp+6
max equ bp+4
Proc getline
push bp ;Set up stack frame
mov bp,sp
pusha ;Save registers
call getctype ;Save cursor type
mov [gl_buf],ax
call getx ;Save cursor position
mov [gl_buf+2],ax
call gety
mov [gl_buf+4],ax
mov [gl_iflag],1 ;Insert initially on
mov bx,[strp] ;Clear the string buffer
mov si,[max]
push bx si 0
call memset
mov di,si ;DI = maximum length
xor si,si ;String pos = 0
sub di,2
mov cx,1 ;Set modify flag
gl_loop: call gl_redraw ;Redraw entry field
gl_kloop: xor ax,ax ;Get a key
int 16h
cmp al,0Dh ;Enter?
je gl_enter
cmp al,1Bh ;Escape?
je gl_esc
cmp al,08h ;Backspace?
je gl_bksp
test al,al ;Alphanumeric char?
jne gl_char
cmp ah,4Bh ;Left?
je gl_left
cmp ah,4Dh ;Right?
je gl_right
cmp ah,47h ;Home?
je gl_home
cmp ah,4Fh ;End?
je gl_end
cmp ah,52h ;Insert?
jne gl_skip0
jmp gl_insert
gl_skip0: cmp ah,53h ;Delete?
jne gl_kloop ;Invalid, loop
jmp gl_delete
;****************** Key Processing Loops
gl_char: mov dl,al ;DL = char
mov ax,[gl_iflag] ;Check insert flag
test ax,ax
jz gl_skip1
push di ;Save DI
gl_sloop1: mov al,[bx+di-1] ;Shift string right
mov [bx+di],al
dec di
cmp di,si
ja gl_sloop1
pop di ;Restore DI
gl_skip1: inc cx ;Set modify flag
mov [bx+si],dl ;Store char
cmp si,di ;Already at right?
je gl_loop
inc si ;Move right
jmp gl_loop ;Loop back
gl_enter: push si
mov si,di ;SI = maximum+1
inc si
gl_sloop0: test si,si ;Hit the left?
jz gl_cont
cmp [byte bx+si-1],0 ;End of string?
jne gl_cont
dec si ;Move left
jmp gl_sloop0 ;Loop back
gl_cont: mov dx,si ;DX = end point
pop si ;Restore SI
cmp dx,[min] ;Below minimum, ignore
jae gl_finish ;Otherwise, quit
gl_jmpk: jmp gl_kloop
gl_esc: push bx di 0 ;Clear buffer...
call memset
xor si,si
call gl_redraw
jmp gl_done
gl_bksp: test si,si ;Can't backspace from
jz gl_jmpk ;the first char
dec si ;Delete at SI-1
jmp gl_delete
gl_left: test si,si ;Already at left?
jz gl_jmpk
dec si ;Move left
jmp gl_loop ;Loop back
gl_right: cmp si,di ;Already at right?
jae gl_jmpk
inc si ;Move right
jmp gl_loop ;Loop back
gl_home: xor si,si ;Move to left
gl_jmp: jmp gl_loop ;Loop back
gl_end: mov si,di ;SI = maximum
cmp [byte bx+si],0 ;Buffer full, move to end
jne gl_jmp
gl_sloop2: test si,si ;Hit the left?
jz gl_jmp
cmp [byte bx+si-1],0 ;End of string?
jne gl_jmp
dec si ;Move left
jmp gl_sloop2 ;Loop back
gl_insert: mov ax,1 ;Toggle insert flag
sub ax,[gl_iflag]
mov [gl_iflag],ax
jmp gl_loop ;Loop back
gl_delete: push si ;Save SI
inc si
gl_sloop3: mov ax,[bx+si] ;Shift string left
mov [bx+si-1],al
inc si
cmp si,di
jbe gl_sloop3
pop si ;Restore SI
mov [byte bx+di],0 ;End with space
inc cx ;Set modify flag
jmp gl_loop ;Loop back
;****************** End of Key Processing
gl_finish: mov si,dx ;SI = length
mov [byte bx+si],0 ;Terminate with a null
gl_done: push [gl_buf+2] ;Restore cursor position
push [gl_buf+4]
call gotoxy
push [gl_buf] ;Restore cursor type
call setctype
popa ;Restore registers
pop bp ;Delete stack frame
ret 10 ;Return
gl_redraw: pusha ;Save all registers
test cx,cx ;Check modify flag
jz gl_setcur
mov cx,[x] ;Set up to clear the field
push cx
add cx,di ;Clear the field
push cx [y] [gl_fillchar]
call hline
push [x] [y] bx ;Show the string
call tputs
gl_setcur: mov ax,[x] ;Set the cursor position
add ax,si
push ax [y]
call gotoxy
mov bx,[gl_iflag] ;AX = cursor to use
add bx,bx
mov ax,[gl_curs+bx]
push ax ;Set cursor type
call setctype
popa ;Restore registers
xor cx,cx ;Reset modify flag
ret ;Return
gl_buf dw 3 dup(0) ;Scratch buffer
gl_iflag dw 0 ;Insert flag
gl_curs dw 000Dh,0C0Dh ;Cursors
gl_fillchar dw 0020h ;Fill char (space)
EndP getline
End
~~~C_AMOUSE
Ideal
Public minit, mclose, mshow, mhide
Public mget, mgetdn, mgetup
Model Tiny
P186
CodeSeg
;****************** Mouse Data
M_X dw 0 ;Mouse X
M_Y dw 0 ;Mouse Y
ScrnBuf dw 0 ;Screen buffer
MouseFound dw 0 ;Existence flag
MouseOn dw 0 ;Display flag
;****************** INTERNAL PROC MouseHandler
Proc MouseHandler
cmp [cs:MouseOn],0 ;Cursor off, skip
je MH_Skip
call PutCursor ;Toggle cursor off
mov [cs:M_X],cx ;Set X, Y
mov [cs:M_Y],dx
call PutCursor ;Toggle cursor on
MH_Skip: retf ;Return
EndP MouseHandler
;****************** INTERNAL PROC PutCursor
Proc PutCursor
pusha ;Save all registers
push ds
push 0A000h ;DS = video memory
pop ds
mov bx,[cs:M_Y] ;AX, BX = X, Y
mov ax,[cs:M_X]
shl bx,5 ;BX = offset
shr ax,2
add bx,ax
xor [byte bx+1],77h ;Toggle cursor
pop ds ;Restore registers
popa
ret ;Return
EndP PutCursor
;****************** minit() -- Initialize mouse system
;int minit(void);
Proc minit
pusha ;Save all registers
xor ax,ax ;Initialize mouse
int 33h
test ax,ax
jz im_nomouse
mov ax,7 ;Set X limits
xor cx,cx ;(90 * 8) - 1
mov dx,719
int 33h
mov ax,8 ;Set Y limits
xor cx,cx ;(34 * 8) - 1
mov dx,271
int 33h
mov ax,3 ;Get position
int 33h
mov [M_X],cx ;Save position
mov [M_Y],dx
push es ;Save ES
push cs ;ES:DX = mouse handler
pop es
mov dx,offset MouseHandler
mov ax,0Ch ;Set handler
mov cx,1 ;for motion
int 33h
mov [MouseOn],0 ;Mouse is off
pop es ;Restore ES
mov [MouseFound],1 ;Set mouse flag
popa ;Restore registers
mov ax,1 ;Return 1
ret
im_nomouse: mov [MouseFound],0 ;Reset mouse flag
popa ;Restore registers
xor ax,ax ;Return 0
ret
EndP minit
;****************** mclose() -- End mouse system
;void mclose(void);
Proc mclose
mov [MouseFound],0 ;Reset mouse flag
cmp [MouseOn],0 ;Mouse off, skip
je em_Off
mov [MouseOn],0 ;Reset cursor flag
call PutCursor ;Hide mouse cursor
em_Off: push ax ;Save AX
xor ax,ax ;Reinitialize mouse
int 33h
pop ax ;Restore AX
ret ;Return
EndP mclose
;****************** mshow() -- Show mouse cursor
;void mshow(void);
Proc mshow
cmp [MouseOn],1 ;Already on, do nothing
je sm_done
call PutCursor ;Show mouse cursor
mov [MouseOn],1 ;Set cursor flag
sm_done: ret ;Return
EndP mshow
;****************** mhide() -- Hide mouse cursor
;void mhide(void);
Proc mhide
cmp [MouseOn],0 ;Already off, do nothing
je hm_done
mov [MouseOn],0 ;Reset cursor flag
call PutCursor ;Hide mouse cursor
hm_done: ret ;Return
EndP mhide
;****************** mget() -- Get mouse position - returns AX,BX,CX
;(int, int, int) mget(void);
Proc mget
push dx ;Save registers
mov ax,3 ;Get mouse position
int 33h
shr cx,3 ;Fix values
shr dx,3
mov ax,bx ;Return AX = button state,
mov bx,cx ; BX = X value, and
mov cx,dx ; CX = Y value
pop dx ;Restore registers
ret ;Return
EndP mget
;****************** mgetdn() -- Get mouse press info - returns AX,BX,CX
;(int, int, int) mgetdn(int btn);
Proc mgetdn
push bp ;Set up stack frame
mov bp,sp
push dx ;Save registers
mov ax,5 ;Get mouse press info
mov bx,[bp+4]
int 33h
shr cx,3 ;Fix values
shr dx,3
mov ax,bx ;Return AX = press count,
mov bx,cx ; BX = X value, and
mov cx,dx ; CX = Y value
pop dx ;Restore registers
pop bp ;Delete stack frame
ret 2 ;Return
EndP mgetdn
;****************** mgetup() -- Get mouse release info - returns AX,BX,CX
;(int, int, int) mgetup(int btn);
Proc mgetup
push bp ;Set up stack frame
mov bp,sp
push dx ;Save registers
mov ax,6 ;Get mouse release info
mov bx,[bp+4]
int 33h
shr cx,3 ;Fix values
shr dx,3
mov ax,bx ;Return AX = release count,
mov bx,cx ; BX = X value, and
mov cx,dx ; CX = Y value
pop dx ;Restore registers
pop bp ;Delete stack frame
ret 2 ;Return
EndP mgetup
End